#include<iostream>
using namespace std;
const int N = 1e6 + 10;
int main()
{
	long long n, m, a[N] = { 0 }, b[N] = { 0 };
	cin >> n >> m;
	long long M = m, sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = n - 1; i >= 0; i--)
	{
		b[i] = b[i + 1] + a[i];
	}
	for (int i = 0; i < n; i++)
	{
		M = M - a[i];
		if (M <= 0)
		{
			cout << "NO";
			return 0;
		}
		if (a[i] == 0 && M <= b[i + 1])//如果血量小于等于后面的所以数字之和就加血
		{
			sum = sum + m - M;
			M = m;
		}
	}
	sum = sum + n - 1;
	cout << sum << endl;
	system("paise");
	return 0;
}
